package cn.i7baozh.boot.learn.autoconfig;

import a.b.c.d.service.ImportTestComponent;
import cn.i7baozh.service.HelloService;
import cn.i7baozh.service.HiService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 1. 验证自定义starter
 * 2. 验证@Import注解
 * @author zhangbaoqi532
 * @date 2025/1/13
 */
@Component
public class AutoConfigTest implements CommandLineRunner {

    @Autowired(required = false)
    private HelloService helloService;

    @Autowired(required = false)
    private HiService hiService;

    @Resource
    private List<ImportTestComponent> importTestComponents;

    @Override
    public void run(String... args) throws Exception {
        helloService.print();
        if (hiService != null) {
            hiService.printProperties();
        }
        for (ImportTestComponent importTestComponent : importTestComponents) {
            importTestComponent.print();
        }
    }
}
